/**
 * 函数组合结合律
 */

const compose =  (...fns) => value =>
  fns.reverse().reduce((value, fn) => fn(value), value)

const reverse = arr => arr.reverse()
const first = arr => arr[0]
const toUpper = str => str.toUpperCase()

// const f = compose(toUpper, first, reverse)
// console.log(f(['hello fp', 'hello compose', 'hello flowRight']))

// const f = compose(compose(toUpper, first), reverse)
// console.log(f(['hello fp', 'hello compose', 'hello flowRight']))

const f = compose(toUpper, compose(first, reverse))
console.log(f(['hello fp', 'hello compose', 'hello flowRight']))

export {}
